package org.evej.apiparser.parser.handler.character;


import org.evej.apiparser.model.character.ApiBalance;
import org.evej.apiparser.parser.handler.ApiDocumentHandler;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;

public class BalanceHandler extends ApiDocumentHandler<ApiBalance> {

    private ApiBalance.Builder builder = new ApiBalance.Builder();

    @Override
    public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
        if ("row".equals(qName)) {
            builder.setAccountId(attributeToInt(attrs, "accountID"));
            builder.setAccountKey(attributeToInt(attrs, "accountKey"));
            builder.setBalance(attributeToDouble(attrs, "balance"));
        }
        super.startElement(uri, localName, qName, attrs);    //To change body of overridden methods use File | Settings | File Templates.
    }

    @Override
    public void endDocument() throws SAXException {
        super.documentModel = builder.build();
        super.endDocument();
    }
}
